package ecstore.client.customWidgets;

import java.util.ArrayList;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.HasVerticalAlignment;

import ecstore.client.dataOperation.ItemInfo;


public class ItemListPanel extends Composite {
	String title;
	VerticalPanel verticalPanel = new VerticalPanel();
	Label titleLabel = new Label("Search results");
	private final ListBox listBox = new ListBox();
	private final HorizontalPanel horizontalPanel = new HorizontalPanel();
	private ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
	
	public ItemListPanel() {
		
		initWidget(verticalPanel);
		verticalPanel.setSize("455px", "317px");
		
		titleLabel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		verticalPanel.add(titleLabel);
		
		
		verticalPanel.add(listBox);
		listBox.setSize("422px", "242px");
		listBox.setVisibleItemCount(10);

		horizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		horizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		
		verticalPanel.add(horizontalPanel);
		horizontalPanel.setWidth("269px");

	}
	
	public void setTitle(String title){
		titleLabel.setText(title);
	}
	
	public void addItem(ItemInfo item){
		listBox.addItem(item.getName() + " " + item.getSize());
		items.add(item);
	}
	
	public void clear(){
		listBox.clear();
	}
	
	public int getSelectedIndex(){
		return listBox.getSelectedIndex();
	}
	
	public ItemInfo getSelectedItem(){
		return items.get(getSelectedIndex());
	}

}
